package com.chixing.controller;

import com.chixing.pojo.Customer;
import com.chixing.service.UserService;
import com.chixing.util.DateUtil;
import com.chixing.util.ServerResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

@Controller
public class UserController {
    @Autowired
    private UserService userService;
    //添加用户信息
//    @PostMapping("customer")
//    public ModelAndView save(Customer customer){
//        ModelAndView mav = new ModelAndView();
//        ServerResponse serverResponse = userService.save(customer);
//        if (serverResponse.getCode()==200){
//            ServerResponse serverResponse1 = userService.getById(customer.getCustId());
//            mav.addObject("serverresponse1",serverResponse1);
//            return mav;
//        }else {
//            mav.addObject("addMessage","添加失败");
//        }
//        return mav;
//    }
    @GetMapping("center/user/{custId}")
    @ResponseBody
    public ServerResponse getById(@PathVariable("custId") Integer custId){
        return userService.getById(custId);
    }
    @GetMapping("user")
    public ModelAndView addUser(Integer custId, Long custTelno, String custPassword,
                                String custName, String custGender, String driverAdd,
                                String driverBirth, String other1, String driverBir,
                                String starttime,String endtime){
        ModelAndView mav = new ModelAndView();
        Customer customer = new Customer();
        customer.setCustId(custId);
        customer.setCustTelno(custTelno);
        customer.setCustPassword(custPassword);
        customer.setCustName(custName);
        customer.setCustGender(custGender);
        customer.setDriverBirth(driverBirth);
        customer.setDriverAdd(driverAdd);
        customer.setOther1(other1);
        customer.setDriverBir(DateUtil.stringToDate(driverBir,"yyyyMMdd"));
        customer.setStarttime(DateUtil.stringToDate(starttime,"yyyyMMdd"));
        customer.setEndtime(DateUtil.stringToDate(endtime,"yyyyMMdd"));
        userService.save(customer);
        mav.setViewName("center/user");
        return mav;
    }


}
